﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class UIVRP : ViewBase
    {
        TVKZUAB cZBP
        {
            get
            {
                return (TVKZUAB)FindName("cZBP");
            }
        }
        public UIVRP()
        {

        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
        }
        public override void vwMaster_CurrentChanged(object sender, System.EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                KEY = "";
                VART = "";
                VVKP = "";
                AUF = "";
            }
            else
            {
                KEY = dwMaster["VRPRENR"].ToString() + dwMaster["VRPREPOS"].ToString();
                VVKP = dwMaster["VRPAUFKRS"].ToString() + dwMaster["VRPAUFLFD"].ToString() + dwMaster["VRPAUFPOS"].ToString();
                VART = dwMaster["VRPKOLL"].ToString() + dwMaster["VRPART"].ToString() + dwMaster["VRPFARBE"].ToString();
                AUF = "R" + dwMaster["VRPRENR"].ToString() + dwMaster["VRPREPOS"].ToString() + KUNDNR.PadRight(8); ;
            }
            if (cZBP != null)
            {
                cZBP.IsAuto = false;
            }
        }
        public override void OnSave()
        {
            if (!IsSaved)
                return;
            foreach (DataRow row in TBMain.Rows)
            {
                if (row.RowState == DataRowState.Unchanged) continue;
                TMV.UpdateVRPOS(row, 0);
            }
            base.OnSave();
        }

        public override void NewCommand(object sender, RoutedEventArgs e)
        {
            if (!IsNew)
            {
                AUFART = "";
                IsNew = true;
                return;
            }
            if (AUFART.Trim().Length == 0)
            {
                MessageBox.Show("必须选择手工发票类型");
                return;
            }
            if (dwMaster == null)
                return;
            dwData = TBMain.NewRow();
            dwData.ItemArray = dwMaster.ItemArray;
            TMV.GetPOS(dwData, 9);
            dwData["VRPWAWERT"] = "0000000000";
            dwData["VRPGESWERT"] = 0;
            dwData["VRPROHWERT"] = 0;
            dwData["VRPMENGET4"] = 0;
            dwData["VRPPREIS"] = 0;
            dwData["VRPERLKZ"] = " ";
            dwData["VRPBONKZ"] = "N";
            dwData["VRPAEDATUM"] = 0;
            dwData["VRPVGBETRAG"] = 0;
            TMV.REMOVEADD(dwData);
            switch (AUFART)
            {
                case "KF":
                    dwData["VRPAPOSTYP"] = "F+ ";
                    dwData["VRPZOLLTNR"] = "7:100               ";
                    dwData["VRPBONKZ"] = "J";
                    dwData["VRPMENGE"] = QTY;
                    dwData["VRPGESWERT"] = 0;
                    dwData["VRPROHWERT"] = SVALUE;
                    //dwData["VRPERLKZ"] = "J";//是否已经计算佣金
                    dwData["VRPPREIS"] = dwMaster["VRPPREIS"];
                    break;
                case "EF":
                    dwData["VRPAPOSTYP"] = "E- ";
                    dwData["VRPZOLLTNR"] = "7:100               ";
                    dwData["VRPBONKZ"] = "J";
                    dwData["VRPMENGE"] = QTY;
                    dwData["VRPGESWERT"] = 0;
                    dwData["VRPROHWERT"] = SVALUE;
                    //dwData["VRPERLKZ"] = "J";//是否已经计算佣金
                    dwData["VRPPREIS"] = dwMaster["VRPPREIS"];
                    break;
                case "KR":
                    dwData["VRPAPOSTYP"] = "K- ";
                    dwData["VRPZOLLTNR"] = "9:100               ";
                    break;
                case "ER":
                    dwData["VRPAPOSTYP"] = "B+ ";
                    dwData["VRPZOLLTNR"] = "9:100               ";
                    break;
                case "EK":
                    dwData["VRPAPOSTYP"] = "B- ";
                    dwData["VRPZOLLTNR"] = "9:100               ";
                    break;
                default:
                    dwData["VRPAPOSTYP"] = "K+ ";
                    dwData["VRPZOLLTNR"] = "9:100               ";
                    break;
            }
            TMV.Insert(dwData);
            vwMaster.View.MoveCurrentToFirst();
            IsNew = false;
            AUFART = "";
            PM["KUNDNR"] = KUNDNR;
            TMV.KD.KDUPDATE(PM);
            base.NewCommand(sender, e);
        }

        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            try
            {
                if (dwMaster == null)
                    return;
                if (dwMaster["VRPERLKZ"].ToString() == "J")
                {
                    throw new Exception("已经支付，禁止删除");
                }
                if (!dwMaster["VRPZOLLTNR"].ToString().StartsWith("9:"))
                {

                    throw new Exception("非手工发票，禁止删除");
                }
                dwData["VRPZOLLTNR"] = "9:100               ";

                filter = "VRPRENR='" + dwMaster["VRPRENR"].ToString() + "' AND VRPREPOS='" + dwMaster["VRPREPOS"].ToString() + "'";
                vwMaster.View.MoveCurrentTo(-1);
                rows = TBMain.Select(filter);
                foreach (DataRow row in rows)
                {
                    ((VVRPOS)MV).DeleteVRPOS(row, 1);
                    row.Delete();
                }
                TBMain.AcceptChanges();
                base.DeleteCommand(sender, e);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }


        public void LineZUABCommand(object sender, RoutedEventArgs e)
        {
            if (cZBP == null)
                return;
            if (dwMaster["VRPZOLLTNR"].ToString().StartsWith("0:"))
            {
                MessageBox.Show("控制行禁止附加费");
                return;
            }

            cZBP.IsAuto = true;
            string _auf = AUF;
            cZBP.ORDERNUM = "";
            cZBP.ORDERNUM = _auf;
        }

        public void ConfirmLineZUABCommand(object sender, RoutedEventArgs e)
        {
            if (cZBP == null)
                return;
            if (dwMaster == null)
                return;
            ((VVRPOS)MV).RESETVRP(dwMaster, cZBP.dwMaster);
            cZBP.IsAuto = false;
        }

        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length < 11)
                return;
            dwData = TBMain.NewRow();
            dwData["VRPMANDANT"] = app.Mandant;
            dwData["VRPRENR"] = ORDERNUM.Substring(0, 8);
            dwData["VRPREPOS"] = ORDERNUM.Substring(8, 3);
            SResult = ((VVRPOS)MV).QueryVRPOS(dwData, 1);
            MergeData(SResult);
            base.LOADBYAUF();
        }

        public virtual void LOADBYVKP(string order)
        {
            TBMain.Clear();
            if (order.Length < 11)
                return;
            dwData = TBMain.NewRow();
            dwData["VRPMANDANT"] = app.Mandant;
            dwData["VRPAUFKRS"] = order.Substring(1, 2);
            dwData["VRPAUFLFD"] = order.Substring(3, 6);
            dwData["VRPAUFPOS"] = order.Substring(9, 3);
            dwData["VRPSTATIST"] = order.Substring(0, 1);
            SResult = ((VVRPOS)MV).QueryVRPOS(dwData, 4);
            MergeData(SResult);
        }

        public virtual void LOADBYEKP(string order)
        {

            LOADBYVKP(order);
        }

        public virtual void LOADBYVKK(string value)
        {
            TBMain.Clear();
            if (!IsCanLoad)
                return;
            if (value.Length < 8)
                return;
            dwData = TBMain.NewRow();
            dwData["VRPMANDANT"] = app.Mandant;
            dwData["VRPAUFKRS"] = value.Substring(1, 2);
            dwData["VRPAUFLFD"] = value.Substring(3, 6);
            dwData["VRPSTATIST"] = value.Substring(0, 1);
            //AND VRPRENR=:VRPRENR:
            SResult = TMV.QVRP06(dwData);
            MergeData(SResult);
        }

        public virtual void LOADBYRENR(string value)
        {
            TBMain.Clear();
            if (value.Length < 2)
                return;
            dwData = TBMain.NewRow();
            dwData["VRPMANDANT"] = app.Mandant;
            dwData["VRPRENR"] = value.Substring(0, 8);
            SResult = TMV.QueryVRPOS(dwData, 2);
            MergeData(SResult);
        }

        public void OnVARTChg(string value)
        {
            if (IsEdit)
                return;
            if (dwMaster == null)
                return;
            if (value.Length < 39)
                return;
            dwMaster["VRPKOLL"] = value.Substring(0, 5);
            dwMaster["VRPART"] = value.Substring(5, 24);
            dwMaster["VRPFARBE"] = value.Substring(29, 10);

        }

        public void OnZUARTChg(string value)
        {
            if (IsEdit)
                return;
            if (dwMaster == null)
                return;
            if (value.Length < 3)
                return;
            dwMaster["VRPZUART1"] = value.PadRight(3);
            MV.OnPropertyChanged("VRPZUART1");

        }

        public void LinePaid(DataRow dwLine, bool IsVK, bool IsVV, bool IsRest)
        {
            try
            {


                if (dwLine == null)
                    throw new Exception("没有找到可以支付记录");
                if (dwLine["VRPERLKZ"].ToString() == "J")//已经支付的，不再处理
                    throw new Exception("已经支付的，不再处理");

                if (dwLine["VRPZOLLTNR"].ToString().StartsWith("0:"))
                    throw new Exception("此行不可以支付");
                if (dwLine["VRPZOLLTNR"].ToString().StartsWith("1:"))
                {
                    Tracer.Info("定金支付", "开始");
                    IsVK = true;
                }
                if (dwLine["VRPZOLLTNR"].ToString().StartsWith("2:"))
                {
                    Tracer.Info("提货款支付", "开始");
                    IsVV = true;
                }
                if (dwLine["VRPZOLLTNR"].ToString().StartsWith("3:"))
                {
                    Tracer.Info("尾款支付", "开始");
                    IsRest = true;
                }
                double value = System.Convert.ToDouble(dwLine["VRPGESWERT"].ToString()) * 0.001;
                if (value == 0 && !IsRest)
                {
                    Tracer.Info("发票支付", "支付金额为0，并且不是尾款,未支付");
                    return;
                }
                //SVALUE本次支付金额
                if (value < 待处理现金)
                {
                    //MessageBox.Show("支付金额为" + value + ",多余部分请转入下一个发票，本发票仅仅接受和发票金额相同部分。若发票金额与支付金额不符合，请更改发票金额");
                    待处理现金 = 待处理现金 - value;
                }
                if (value > 待处理现金 + SVALUE)
                {
                    MessageBox.Show("支付金额为" + value + ",不能满足本发票需求,将记录到客户信用里面");
                    //待处理现金 = SVALUE;
                    //((VVRPOS)MV).UpdateVRPOS(dwMaster, 0);
                    return;
                }
                已付款 = 已付款 + value;
                dwLine["VRPAEDATUM"] = MV.date;
                dwLine["VRPERLKZ"] = "J";
                dwLine["VRPBONKZ"] = "J";
                dwLine["VRPVGBETRAG"] = double.Parse(dwLine["VRPGESWERT"].ToString()) * 0.001;

                ((VVRPOS)MV).UpdateVRPOS(dwLine, 0);
                if (IsVK)
                {
                    VKPPay(dwLine);
                }
                if (IsVV)
                {
                    VVPay(dwLine);
                }
                if (IsRest)
                {
                    VKPRestPay(dwLine);
                }
                SVALUE = 0;
                PM["KUNDNR"] = KUNDNR;
                TMV.KD.KDUPDATE(PM);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            } 
        }

        public void ManulPaid(DataRow dwLine, bool IsVK, bool IsVV, bool IsRest)
        {
            try
            {

                if (SVALUE > 9999999)
                {
                    MessageBox.Show("达到千万，超出单行的最大支付金额，请拆分付款方式，分开支付");
                    return;
                }
                if (dwLine == null)
                    return;
                if (dwLine["VRPERLKZ"].ToString() == "J")//已经支付的，不再处理
                    return;
                if (dwLine["VRPZOLLTNR"].ToString().StartsWith("0:"))
                    return;
                if (dwLine["VRPZOLLTNR"].ToString().StartsWith("1:"))
                {
                    IsVK = true;
                }
                if (dwLine["VRPZOLLTNR"].ToString().StartsWith("2:"))
                {
                    IsVV = true;
                }
                if (dwLine["VRPZOLLTNR"].ToString().StartsWith("3:"))
                {
                    IsRest = true;
                }

                已付款 = 已付款 + SVALUE;
                dwLine["VRPAEDATUM"] = MV.date;
                dwLine["VRPERLKZ"] = "J";
                dwLine["VRPBONKZ"] = "J";
                dwLine["VRPVGBETRAG"] = double.Parse(dwLine["VRPGESWERT"].ToString()) * 0.001;
                dwLine["VRPGESWERT"] = Helper.Right("0000000000" + (SVALUE * 1000).ToString(), 10);

                ((VVRPOS)MV).UpdateVRPOS(dwLine, 0);
                if (IsVK)
                {
                    VKPPay(dwLine);
                }
                if (IsVV)
                {
                    VVPay(dwLine);
                }
                if (IsRest)
                {
                    VKPRestPay(dwLine);
                }
                SVALUE = 0;
                PM["KUNDNR"] = KUNDNR;
                TMV.KD.KDUPDATE(PM);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        public void VKPPay(DataRow dwLine)
        {

            PM["KRS"] = dwLine["VRPAUFKRS"].ToString();
            PM["LFD"] = dwLine["VRPAUFLFD"].ToString();
            PM["POS"] = dwLine["VRPAUFPOS"].ToString();
            TMV.VVKP.VKPPay(PM);
        }

        public void VKPRestPay(DataRow dwLine)
        {
            PM["ORDERNUM"] = dwLine["VRPAUFKRS"].ToString() + dwLine["VRPAUFLFD"].ToString() + dwLine["VRPAUFPOS"].ToString();
            PM["AUFTYP"] = dwLine["VRPSTATIST"].ToString();
            PM["KRS"] = dwLine["VRPAUFKRS"].ToString();
            PM["LFD"] = dwLine["VRPAUFLFD"].ToString();
            PM["POS"] = dwLine["VRPAUFPOS"].ToString();
            TMV.VVKP.VKPRestPay(PM);
        }

        public void VVPay(DataRow dwLine)
        {
            PM["LIEFSCH"] = dwLine["VRPLIEFSCH"].ToString();
            ((VVRPOS)MV).VV.VVPay(PM);
        }

        public void ConfirmPaymentCommand(object sender, RoutedEventArgs e)
        {

            if (dwMaster == null)
                return;
            double value = System.Convert.ToDouble(dwMaster["VRPGESWERT"].ToString()) * 0.001;
            if (!IsNew)
            {
                IsNew = true;
                SVALUE = value;
                MessageBox.Show("请确认金额");
                return;
            }
            LinePaid(dwMaster, false, false, false);
            SVALUE = 0;
            IsNew = false;
            IsRest = false;
            IsVKPay = false;
            IsVVPay = false;
            base.SaveCommand(sender, e);

        }

        public override void SetUpUserRight()
        {
            base.SetUpUserRight();
            Type mom = this.GetType();
            if (mom == null)
                return;
            string filter = "USERID='" + app.User + "' AND PROG='" + mom.Name.PadRight(80) + "'";
            DataRow[] rows = TBUR.Select(filter);
            foreach (DataRow row in rows)
            {
                string contol = row["CONTROLS"].ToString();//属性 
                string PROCESS = row["PROCESS"].ToString();//控制值
                string txt = row["P0"].ToString();//文本值 
                bool blControl = true;
                if (PROCESS.Trim() == "N")
                {
                    blControl = false; ;
                }
                if (PROCESS.Trim() == "Y")
                {
                    blControl = true; ;
                }
                switch (contol.Trim())
                {
                    case "PAY":
                        IsCanPay = blControl;
                        break;
                    case "CHGZA":
                        IsChgZA = blControl;
                        break;
                }
            }
        }


    }
    public partial class UIVRP : ViewBase
    {

        public VVRPOS TMV
        {
            get
            {
                return (VVRPOS)MV;
            }
        }
        #region ==AUF===========
        public static readonly DependencyProperty AUFProperty = DependencyProperty.Register("AUF",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAUFChanged));
        public string AUF
        {
            get
            {
                return (string)GetValue(AUFProperty);
            }
            set
            {
                SetValue(AUFProperty, value);
            }
        }
        private static void OnAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.AUF = (string)e.NewValue;
            }
        }
        #endregion


        #region ==IsBlocked===========
        public static readonly DependencyProperty IsBlockedProperty = DependencyProperty.Register("IsBlocked",
            typeof(bool), typeof(UIVRP),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsBlockedChanged));
        public bool IsBlocked
        {
            get
            {
                return (bool)GetValue(IsBlockedProperty);
            }
            set
            {
                SetValue(IsBlockedProperty, value);
            }
        }
        private static void OnIsBlockedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.IsBlocked = (bool)e.NewValue;
            }
        }
        #endregion
        #region ==IsChgZA===========
        public static readonly DependencyProperty IsChgZAProperty = DependencyProperty.Register("IsChgZA",
            typeof(bool), typeof(UIVRP),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsChgZAChanged));
        public bool IsChgZA
        {
            get
            {
                return (bool)GetValue(IsChgZAProperty);
            }
            set
            {
                SetValue(IsChgZAProperty, value);
            }
        }
        private static void OnIsChgZAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.IsChgZA = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCanPay===========
        public static readonly DependencyProperty IsCanPayProperty = DependencyProperty.Register("IsCanPay",
            typeof(bool), typeof(UIVRP),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanPayChanged));
        public bool IsCanPay
        {
            get
            {
                return (bool)GetValue(IsCanPayProperty);
            }
            set
            {
                SetValue(IsCanPayProperty, value);
            }
        }
        private static void OnIsCanPayChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.IsCanPay = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsVKPay===========
        public static readonly DependencyProperty IsVKPayProperty = DependencyProperty.Register("IsVKPay",
            typeof(bool), typeof(UIVRP),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsVKPayChanged));
        public bool IsVKPay
        {
            get
            {
                return (bool)GetValue(IsVKPayProperty);
            }
            set
            {
                SetValue(IsVKPayProperty, value);
                IsSaved = !value;
            }
        }
        private static void OnIsVKPayChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.IsVKPay = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsMPay===========
        public static readonly DependencyProperty IsMPayProperty = DependencyProperty.Register("IsMPay",
            typeof(bool), typeof(UIVRP),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsMPayChanged));
        public bool IsMPay
        {
            get
            {
                return (bool)GetValue(IsMPayProperty);
            }
            set
            {
                SetValue(IsMPayProperty, value);
                IsSaved = !value;
            }
        }
        private static void OnIsMPayChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.IsMPay = (bool)e.NewValue;
                src.OnMPayChg((bool)e.NewValue);
            }
        }
        public virtual void OnMPayChg(bool _IsMPay)
        {

        }
        #endregion
        #region ==EXPAY===========
        public static readonly DependencyProperty EXPAYProperty = DependencyProperty.Register("EXPAY",
            typeof(double), typeof(UIVRP),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEXPAYChanged));
        public double EXPAY
        {
            get
            {
                return (double)GetValue(EXPAYProperty);
            }
            set
            {
                SetValue(EXPAYProperty, value);
            }
        }
        private static void OnEXPAYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.EXPAY = (double)e.NewValue;
                src.OnEXPAYChg((double)e.NewValue);
            }
        }
        public virtual void OnEXPAYChg(double _EXPAY)
        {

        }
        #endregion

        #region ==IsVVPay===========
        public static readonly DependencyProperty IsVVPayProperty = DependencyProperty.Register("IsVVPay",
            typeof(bool), typeof(UIVRP),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsVVPayChanged));
        public bool IsVVPay
        {
            get
            {
                return (bool)GetValue(IsVVPayProperty);
            }
            set
            {
                SetValue(IsVVPayProperty, value);
                IsSaved = !value;
            }
        }
        private static void OnIsVVPayChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.IsVVPay = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsRest===========
        public static readonly DependencyProperty IsRestProperty = DependencyProperty.Register("IsRest",
            typeof(bool), typeof(UIVRP),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsRestChanged));
        public bool IsRest
        {
            get
            {
                return (bool)GetValue(IsRestProperty);
            }
            set
            {
                SetValue(IsRestProperty, value);
                IsSaved = !value;
            }
        }
        private static void OnIsRestChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.IsRest = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==KUNDNR===========
        public static readonly DependencyProperty KUNDNRProperty = DependencyProperty.Register("KUNDNR",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKUNDNRChanged));
        public string KUNDNR
        {
            get
            {
                return (string)GetValue(KUNDNRProperty);
            }
            set
            {
                SetValue(KUNDNRProperty, value);
            }
        }
        private static void OnKUNDNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.KUNDNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsPaid===========
        public static readonly DependencyProperty IsPaidProperty = DependencyProperty.Register("IsPaid",
            typeof(bool), typeof(UIVRP),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsPaidChanged));
        public bool IsPaid
        {
            get
            {
                return (bool)GetValue(IsPaidProperty);
            }
            set
            {
                SetValue(IsPaidProperty, value);
                OnPaidChg(value);
            }
        }
        private static void OnIsPaidChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.IsPaid = (bool)e.NewValue;
            }
        }
        public virtual void OnPaidChg(bool paied)
        { }
        #endregion

        #region ==IsKDReload===========
        public static readonly DependencyProperty IsKDReloadProperty = DependencyProperty.Register("IsKDReload",
            typeof(bool), typeof(UIVRP),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsKDReloadChanged));
        public bool IsKDReload
        {
            get
            {
                return (bool)GetValue(IsKDReloadProperty);
            }
            set
            {
                SetValue(IsKDReloadProperty, value);
            }
        }
        private static void OnIsKDReloadChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.IsKDReload = (bool)e.NewValue;
            }
        }
        #endregion 

        #region ==VKP===========
        public static readonly DependencyProperty VKPProperty = DependencyProperty.Register("VKP",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKPChanged));
        public string VKP
        {
            get
            {
                return (string)GetValue(VKPProperty);
            }
            set
            {
                SetValue(VKPProperty, value);
                LOADBYVKP(value);
            }
        }
        private static void OnVKPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.VKP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==EKP===========
        public static readonly DependencyProperty EKPProperty = DependencyProperty.Register("EKP",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEKPChanged));
        public string EKP
        {
            get
            {
                return (string)GetValue(EKPProperty);
            }
            set
            {
                SetValue(EKPProperty, value);
                LOADBYEKP(value);
            }
        }
        private static void OnEKPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.EKP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VKK===========
        public static readonly DependencyProperty VKKProperty = DependencyProperty.Register("VKK",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKKChanged));
        public string VKK
        {
            get
            {
                return (string)GetValue(VKKProperty);
            }
            set
            {
                SetValue(VKKProperty, value);
                LOADBYVKK(value);
            }
        }
        private static void OnVKKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.VKK = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VART===========
        public static readonly DependencyProperty VARTProperty = DependencyProperty.Register("VART",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVARTChanged));
        public string VART
        {
            get
            {
                return (string)GetValue(VARTProperty);
            }
            set
            {
                SetValue(VARTProperty, value);
                OnVARTChg(value);
            }
        }
        private static void OnVARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.VART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==ZUART===========
        public static readonly DependencyProperty ZUARTProperty = DependencyProperty.Register("ZUART",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnZUARTChanged));
        public string ZUART
        {
            get
            {
                return (string)GetValue(ZUARTProperty);
            }
            set
            {
                SetValue(ZUARTProperty, value);
                OnZUARTChg(value);
            }
        }
        private static void OnZUARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.ZUART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==RENR===========
        public static readonly DependencyProperty RENRProperty = DependencyProperty.Register("RENR",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRENRChanged));
        public string RENR
        {
            get
            {
                return (string)GetValue(RENRProperty);
            }
            set
            {
                SetValue(RENRProperty, value);
                LOADBYRENR(value);
            }
        }
        private static void OnRENRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.RENR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VVKP===========
        public static readonly DependencyProperty VVKPProperty = DependencyProperty.Register("VVKP",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVVKPChanged));
        public string VVKP
        {
            get
            {
                return (string)GetValue(VVKPProperty);
            }
            set
            {
                SetValue(VVKPProperty, value);
            }
        }
        private static void OnVVKPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.VVKP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==SQTY===========
        public static readonly DependencyProperty SQTYProperty = DependencyProperty.Register("SQTY",
            typeof(double), typeof(UIVRP),
            new FrameworkPropertyMetadata(-1.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSQTYChanged));
        public double SQTY
        {
            get
            {
                return (double)GetValue(SQTYProperty);
            }
            set
            {
                SetValue(SQTYProperty, value);
            }
        }
        private static void OnSQTYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.SQTY = (double)e.NewValue;
            }
        }
        #endregion

        #region ==SVALUE===========
        public static readonly DependencyProperty SVALUEProperty = DependencyProperty.Register("SVALUE",
            typeof(double), typeof(UIVRP),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSVALUEChanged));
        public double SVALUE
        {
            get
            {
                return (double)GetValue(SVALUEProperty);
            }
            set
            {
                SetValue(SVALUEProperty, value);
            }
        }
        private static void OnSVALUEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.SVALUE = (double)e.NewValue;
            }
        }
        #endregion

        #region ==已开票===========
        public static readonly DependencyProperty 已开票Property = DependencyProperty.Register("已开票",
            typeof(double), typeof(UIVRP),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, On已开票Changed));
        public double 已开票
        {
            get
            {
                return (double)GetValue(已开票Property);
            }
            set
            {
                SetValue(已开票Property, value);
            }
        }
        private static void On已开票Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.已开票 = (double)e.NewValue;
            }
        }
        #endregion

        #region ==待处理现金===========
        public static readonly DependencyProperty 待处理现金Property = DependencyProperty.Register("待处理现金",
            typeof(double), typeof(UIVRP),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, On待处理现金Changed));
        public double 待处理现金
        {
            get
            {
                return (double)GetValue(待处理现金Property);
            }
            set
            {
                SetValue(待处理现金Property, value);
            }
        }
        private static void On待处理现金Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.待处理现金 = (double)e.NewValue;
            }
        }
        #endregion

        #region ==已付款===========
        public static readonly DependencyProperty 已付款Property = DependencyProperty.Register("已付款",
            typeof(double), typeof(UIVRP),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, On已付款Changed));
        public double 已付款
        {
            get
            {
                return (double)GetValue(已付款Property);
            }
            set
            {
                SetValue(已付款Property, value);
            }
        }
        private static void On已付款Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.已付款 = (double)e.NewValue;
            }
        }
        #endregion

        #region ==SWING===========
        public static readonly DependencyProperty SWINGProperty = DependencyProperty.Register("SWING",
            typeof(double), typeof(UIVRP),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSWINGChanged));
        public double SWING
        {
            get
            {
                return (double)GetValue(SWINGProperty);
            }
            set
            {
                SetValue(SWINGProperty, value);
            }
        }
        private static void OnSWINGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.SWING = (double)e.NewValue;
            }
        }
        #endregion

        #region ==CREDIT===========
        public static readonly DependencyProperty CREDITProperty = DependencyProperty.Register("CREDIT",
            typeof(double), typeof(UIVRP),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCREDITChanged));
        public double CREDIT
        {
            get
            {
                return (double)GetValue(CREDITProperty);
            }
            set
            {
                SetValue(CREDITProperty, value);
            }
        }
        private static void OnCREDITChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.CREDIT = (double)e.NewValue;
            }
        }
        #endregion

        #region ==KDBLOCK===========
        public static readonly DependencyProperty KDBLOCKProperty = DependencyProperty.Register("KDBLOCK",
            typeof(bool), typeof(UIVRP),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDBLOCKChanged));
        public bool KDBLOCK
        {
            get
            {
                return (bool)GetValue(KDBLOCKProperty);
            }
            set
            {
                SetValue(KDBLOCKProperty, value);
                OnKDBLOCKChg(value);

            }
        }
        private static void OnKDBLOCKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.KDBLOCK = (bool)e.NewValue;
            }
        }
        public void OnKDBLOCKChg(bool value)
        {


        }
        #endregion

        #region ==AUFART===========
        public static readonly DependencyProperty AUFARTProperty = DependencyProperty.Register("AUFART",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAUFARTChanged));
        public string AUFART
        {
            get
            {
                return (string)GetValue(AUFARTProperty);
            }
            set
            {
                SetValue(AUFARTProperty, value);
            }
        }
        private static void OnAUFARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.AUFART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==PAYTYP===========
        public static readonly DependencyProperty PAYTYPProperty = DependencyProperty.Register("PAYTYP",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPAYTYPChanged));
        public string PAYTYP
        {
            get
            {
                return (string)GetValue(PAYTYPProperty);
            }
            set
            {
                SetValue(PAYTYPProperty, value);
            }
        }
        private static void OnPAYTYPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.PAYTYP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==PAIDVALUE===========
        public static readonly DependencyProperty PAIDVALUEProperty = DependencyProperty.Register("PAIDVALUE",
            typeof(string), typeof(UIVRP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPAIDVALUEChanged));
        public string PAIDVALUE
        {
            get
            {
                return (string)GetValue(PAIDVALUEProperty);
            }
            set
            {
                SetValue(PAIDVALUEProperty, value);
            }
        }
        private static void OnPAIDVALUEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVRP;
            if (src != null)
            {
                src.PAIDVALUE = (string)e.NewValue;
                src.OnPAIDVALUEChg((string)e.NewValue);
            }
        }
        public virtual void OnPAIDVALUEChg(string value)
        {

        }
        #endregion
    }
}